const pool = require('../tools/getPool');
const sendResponse = require('../tools/sendResponse');


const fs = require("fs");//操作文件



module.exports = function(req, res, next){

    let on = req.file.originalname;
    let setname = String(new Date().valueOf()) + on.slice(on.lastIndexOf(".")-on.length);

    fs.rename(req.file.path, "public/assets/"+setname, function(err){
        if (err) {
            sendResponse('error','未知错误', {}, res);
            return
        }

        let newpath = "/assets/" + setname;

        let result = {
            "success": true,
            "msg": "ok",
            "file_path": newpath
        }

        res.writeHead(200,{'Content-Type': 'application/json'});
        res.write(JSON.stringify(result));
        res.end();


    })

}
